package il.ac.technion.wiki.api.expressions;

import il.ac.technion.wiki.api.search.Hit;
import il.ac.technion.wiki.api.search.IndexSearcher;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 *	This class is the base of the Composite pattern that respresents the query for Wiki Documents
 */
public abstract class Expression {
	public List<Hit> hits = null;

	protected abstract void evaluate(IndexSearcher iSearcher);

	final Comparator<Hit> SCORE_ORDER = new Comparator<Hit>(){
		public int compare(Hit h1, Hit h2){
			if (h1.getScore() < h2.getScore())
				return 1;
			if (h1.getScore() == h2.getScore())
				return 0;
			return -1;
		}
	};
	public List<Hit> getHits(IndexSearcher iSearcher){
		evaluate(iSearcher);
		Collections.sort(hits, SCORE_ORDER);
		return hits;
	}
}